<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>数据列表</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#btnExport").click(function(){
				top.$.jBox.confirm("确认要导出本页数据吗？","系统提示",function(v,h,f){
					if(v=="ok"){
						$("#searchForm").attr("action","${ctx}/ins/insData/exportList?pagination=true");
						$("#searchForm").submit();
						$("#searchForm").attr("action","${ctx}/ins/insData/dataList");
					}
				},{buttonsFocus:1});
				top.$('.jbox-body .jbox-icon').css('top','55px');
			});
			$("#btnAllExport").click(function(){
				top.$.jBox.confirm("确认要导出全部数据吗？","系统提示",function(v,h,f){
					if(v=="ok"){
						$("#searchForm").attr("action","${ctx}/ins/insData/exportList");
						$("#searchForm").submit();
						$("#searchForm").attr("action","${ctx}/ins/insData/dataList");
					}
				},{buttonsFocus:1});
				top.$('.jbox-body .jbox-icon').css('top','55px');
			});
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		function dataForm(dataId){
			var tableId = $("#tableId").val();
			var url = "${ctx}/ins/insData/fill?ope=update&id="+dataId+"&tableId="+tableId;
			top.$.jBox.open("iframe:"+url, "数据修改",810,$(top.document).height()-120,{
                buttons:{"提交":"ok", "关闭":true}, bottomText:"数据修改",submit:function(v, h, f){
                    var code;
                    if (v=="ok"){
                    	// 执行保存
                        //loading('正在提交，请稍等...');
                    	var flag = h.find("iframe")[0].contentWindow.submitForm();
                    	if(flag){
                    		location.reload();
                    	}
                        return false;
                    }
                }, loaded:function(h){
                    $(".jbox-content", top.document).css("overflow-y","hidden");
                }, closed:function(){
                   		location.reload();
                }
            });
		}
		function dataFillForm(dataId){
			var tableId = $("#tableId").val();
			var url = "${ctx}/ins/insData/fill?id="+dataId+"&tableId="+tableId;
			top.$.jBox.open("iframe:"+url, "数据修改",810,$(top.document).height()-120,{
                buttons:{"提交":"ok", "关闭":true}, bottomText:"数据修改",submit:function(v, h, f){
                    var code;
                    if (v=="ok"){
                    	// 执行保存
                        //loading('正在提交，请稍等...');
                    	var flag = h.find("iframe")[0].contentWindow.submitForm();
                    	if(flag){
                    		location.reload();
                    	}
                        return false;
                    }
                }, loaded:function(h){
                    $(".jbox-content", top.document).css("overflow-y","hidden");
                }, closed:function(){
                   		location.reload();
                }
            });
		}
		function refreshServicePassword(userName){
			return servicePassword(refresh,userName);
		}
		function refresh(){
			loading("刷新中，请稍候。。。");
			var tableId = $("#tableId").val();
			var url = "${ctx}/ins/insData/refresh";
            $.ajax({
                type: 'POST',
                url : url,
                async:false,
                data: {'table.id':tableId},             //获取表单数据
                success : function(data) {
                	if(data != "success"){
                        alertx(data);
                	}else{
                        alertx("数据刷新成功");
                        location.reload();
                	}
                	closeLoading();
                },
                error : function(data){
                	alertx("无权限");
                }
            });
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a id="btn" href="${ctx}/ins/insData/view">数据详细</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="insData"  action="${ctx}/ins/insData/dataList" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="tableId" name="table.id" type="hidden" value="${insData.table.id}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
			<li><label>索引：</label>
				<form:input path="index" htmlEscape="false" maxlength="64" class="input-medium"/>
			</li>
			<li><label>按日期筛选：</label>
				<select name="dateField.id" class="input-medium" data-value="${insData.dateField}">
					<option value=""></option>
					<c:forEach items="${fields}" var="field">
						<option value="${field.id}" <c:if test="${insData.dateField.id==field.id}">selected</c:if>>${field.name}</option>
					</c:forEach>
				</select>
			</li>
			<li><label>起始时间：</label>
    				<input name="dateFrom" id="startTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
    					value="${insData.dateFrom}"
    					onclick="WdatePicker({dateFmt:'yyyy年MM月dd日',isShowClear:true,maxDate:'#F{$dp.$D(\'endTime\')}'});"/>
   			</li>
   			<li><label>结束时间：</label>
   				<input name="dateTo" id="endTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
   					value="${insData.dateTo}"
   					onclick="WdatePicker({dateFmt:'yyyy年MM月dd日',isShowClear:true,minDate:'#F{$dp.$D(\'startTime\')}'});"/>
   			</li>
   			<li><label>表标识：</label>
   				<input type="text" value="${insData.table.tableId}" readonly class="input-medium"/>
   			</li>
   			<li><label>版本号：</label>
   				<input type="text" value="${insData.table.version}" readonly class="input-medium"/>
   			</li>
			<li class="btns">
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
				<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
				<input id="btnExport" class="btn btn-primary" type="button" value="导出本页"/>
				<input id="btnAllExport" class="btn btn-primary" type="button" value="导出全部"/>
				<input id="btnRefresh" onclick="refresh();" class="btn btn-primary" type="button" value="刷新数据"/>
			</li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<!-- <th>名称</th>
				<th>备注</th> -->
				<c:forEach items="${insData.table.insFieldList}" var="field">
					<th><c:if test="${field.indexed==1}"><font color="red">*</font></c:if>${field.name}</th>
				</c:forEach>
				<shiro:hasPermission name="ins:insTable:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="insData">
			<tr>
				<%-- <td><a href="javascript:void(0);" onclick="dataForm('${insData.id}');">
					${insData.name}
				</a></td>
				<td>
					${insData.remarks}
				</td> --%>
				<c:forEach items="${insData.datas}" var="value">
					<td>
						<c:choose>
							<c:when test="${value.overRange=='1'}">
								<font color="red">${value.value}</font>
							</c:when>
							<c:otherwise>${value.value}</c:otherwise>
						</c:choose>
					</td>
				
				</c:forEach>
				<shiro:hasPermission name="ins:insTable:edit"><td>
					<a href="javascript:void(0);" onclick="dataForm('${insData.id}');">修改</a>
					<c:if test="${insData.fillFlag == '1' && fns:getUser().id==insData.createBy.id}">
						<a href="javascript:void(0);" onclick="dataFillForm('${insData.id}');">填报</a>
					</c:if>
					<c:if test="${not empty insData.table.template.id}">
	    				<%-- <a href="javascript:void(0);" onclick="exportWord('${insData.id}');">导出</a> --%>
	    				<a href="${ctx}/ins/insData/print?id=${insData.id}&tableId=${insData.table.id}">PDF</a>
	    				<%--<a href="${ctx}/ins/insData/printPDF?id=${insData.id}&tableId=${insData.table.id}">打印机打印</a> --%>
					</c:if>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>